//    Copyright (C) Kherty.  All rights reserved.
namespace OpenLS.Spreadsheet
{
    public class ContainsBlankFormattingRule : StandardConditionalFormattingRule
    {
        internal override ConditionalFormattingType Type
        {
            get { return ConditionalFormattingType.ContainsBlanks; }
        }
        internal override bool Apply(Cell cell)
        {
            object v = cell.Value;
            bool isNullOrEmpty = v == null;
            if (v is string)
                isNullOrEmpty = string.IsNullOrEmpty((string) v);
            return ApplyStyle(cell, isNullOrEmpty);
        }
        internal override void PrepareBeforeWrite(ConditionalFormatting conditionalFormatting, FormatType formatType)
        {
            var cell = conditionalFormatting.Range.TopLeftCell;
            this.Formula1 = string.Format("=LEN(TRIM({0}))=0", cell.Label);
        }
    }
}
